{% extends "base.html" %}
{% load humanize %}
{% load race_extras %}
{% block filling %}

<div class="incoming-wins" style="float:right">
<div class="update">
    <p><strong>11/24/2008 update</strong></p>
    <p>We've fixed a few bugs, entered a couple more results, and added more
    information about current and prior endorsements.</p>
    <p>The gubernatorial races
    proved to be a bit tricky, and may throw off our numbers a hair.
    <a href="/about#governors">See the about page for the details.</a></p>
    <p>Following the resolution of the last six races, enviroVOTE will go on
    vacation until next year.</p>
    <p>Thanks for tuning in!</p>
</div>
<h2>Incoming wins</h2>
{% ifequal 0 incoming_races.count %}
    <div>
        <h4>Stay tuned!</h4>
        <p>The enviro-meter hasn't moved yet, but very soon it'll show the environmental impact of today's election!</p>
        <p>As the results come in tonight, we'll post them right here.</p>
    </div>
{% else %}
  <p>The latest results in<br/> races we're watching:</p>
    {% for race in incoming_races %}
    <div>
        <h4><a href="{{race.get_absolute_url}}">
        {% ifequal race.race_type 'pre' %}U.S. President{% endifequal %}
        {% ifequal race.race_type 'hou' %}{{race.get_state_display}}, U.S. House{% endifequal %}
        {% ifequal race.race_type 'sen' %}{{race.get_state_display}}, U.S. Senate{% endifequal %}
        {% ifequal race.race_type 'gov' %}{{race.get_state_display}} Governor{% endifequal %}
        </a></h4>
        {% ifequal race.race_type 'hou' %}<h5>{{ race.district_display }}</h5>{% endifequal %}
        <ol>
        {% for candidate in race.candidate_set.all %}
            <li class="{% ifequal race.winner candidate %}winner{% endifequal %}">
          {% ifequal race.winner candidate %}
            <img src="/public/images/star.png" alt="{% if race.projected %}Projected {% endif %}Winner" title="{% if race.projected %}Projected {% endif %}Winner" class="badge"/>
          {% endifequal %}

          {% ifequal race.greenest candidate  %}
            <img src="/public/images/world.png" alt="Most endorsed by environmental groups" title="Most endorsed by environmental groups" class="badge"/>
          {% endifequal %}

            {{candidate.name}} ({{candidate.party_abbv}}) 
            {% if candidate.vote_percentage %}
            {{candidate.vote_percentage|floatformat:2}}%              
            {% endif %}            
            {% ifequal race.winner candidate %}{% if race.projected %} (projected){% endif %}{% endifequal %}
            </li>
        {% endfor %}
        </ol>
        <p class="tally-notes">{{race.tally_notes}}</p>
        <p class="tally-updated">{{race.tally_updated|naturalday|capfirst}} at {{race.tally_updated|date:"h:i a"}}</p>
    </div>
    {% endfor %}
{% endifequal %}
</div>

<div class="center">
    <br/>
    {% show_big_meter meter_info %}
    <br/>
    <h2>Key Races</h2>
    <div class="key-races">
    {% for race in key_races %}
      <div class="key-race">
        {% if race.headline %}
        <h2 style="border:0"><a href="{{race.get_absolute_url}}">{{race.headline}}</a></h2>
        {% else %}
        <h2 style="border:0"><a href="{{race.get_absolute_url}}">{{race.title}}</a></h2>
        {% endif %}
        
          <table border="0" cellpadding="0" cellspacing="0"><tr>
        {% for candidate in race.candidate_set.all %}
            {% if candidate.is_key %}
              <td class="candidate-display{% ifequal race.greenest candidate %} greenest{% endifequal %} {% cycle "first" "last" %}">
              <img height="135" width="110" src="{% firstof candidate.photo "http://www.votesmart.org/canphoto/nophoto.gif" %}" alt="Portrait of {{candidate.name}}"/>
              {% ifequal race.winner candidate %}
                <span class="winner">
                <img src="/public/images/star.png" alt="Star" class="badge"/>
                {% if race.projected %}
                  Projected winner
                {% else %}
                  Winner
                {% endif %}
                </span>
              {% else %}<span class="winner" style="background:transparent">&nbsp;</span>
              {% endifequal %}
              <span class="name">
              {% ifequal race.winner candidate %}
                <strong>{{candidate.name}}</strong>
              {% else %}
                {{candidate.name}}
              {% endifequal %}
              </span>
              <span class="party">({{candidate.party_abbv}})</span>
              {% if candidate.last_elected %}<span class="incumbent">(incumbent)</span>{% endif %}
              {% if candidate.votes %}
                <span class="votes">
                {{candidate.vote_percentage|floatformat:2}}% of the vote
              </span>
              {% else %}
              {% if candidate.vote_pc %}
                <span class="vote">{{ candidate.vote_pc }}</span>
              {% endif %}
              {% endif %}
              <div class="endorsements">
              {% ifnotequal candidate.endorsement_set.all.count 0 %}
              <span class="endorsement">
                {% ifequal race.greenest candidate  %}
                  <img src="/public/images/world.png" alt="Most endorsed by environmental groups" title="Most endorsed by environmental groups" class="badge"/>
                {% endifequal %}
                Endorsed by {{candidate.endorsement_set.all.count|apnumber}} 
                organization{% ifnotequal candidate.endorsement_set.all.count 1 %}s{% endifnotequal %}</span>
              {% else %}
              <span class="endorsement">No endorsements</span>
              {% endifnotequal %}            
              {% ifequal race.greenest candidate %}<span class="greenest">Greenest</span>{% endifequal %}
              </div>
            </td>
            {% endif %}
        {% endfor%}    
          </tr>
        </table>
          <div class="content">
              {% if race.deck %}<h3>{{race.deck}} - {{race.title}}</h3>{% endif %}
              {% if race.vote_last_updated %}
                <p>Last updated at {{race.vote_last_updated|date:"h:i a"}} {{race.vote_last_updated|naturalday}}</p>
              {% endif %}
              {{race.body|linebreaks}}
          </div>
          
      </div>
    {% endfor %}
    </div>
</div>
{% endblock %}
